package com.huage_03.lesson_02;

import com.huage_03.lesson_02.util.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DruidTest {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = DruidUtils.getConnection();
            String sql = "select * from user where id = ? ";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1,2);
            rs = pstmt.executeQuery();
            while (rs.next()){
                String username = rs.getString("username");
                String password = rs.getString("password");
                System.out.println(username + " " + password);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DruidUtils.closeAll(conn,pstmt,rs);
        }
    }
}
